package com.zy.user.service;

/**
 * @program: shopping147_cloud
 * @description: 用于生成 JWT 签名密钥的工具类
 * @author: zy
 * @create: 2025-07-24 16:12
 */
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import java.util.Base64;

public class KeyGenerator {
    public static void main(String[] args) {
        // Generate a secure random key for HS256 (256 bits = 32 bytes)
        byte[] keyBytes = Keys.secretKeyFor(SignatureAlgorithm.HS256).getEncoded();
        // Base64 encode it for storage in properties/environment variable
        String base64EncodedKey = Base64.getEncoder().encodeToString(keyBytes);
        System.out.println("Generated Base64 Encoded Secret Key: " + base64EncodedKey);
        // Example of decoding for verification:
        // byte[] decodedKeyBytes = Base64.getDecoder().decode(base64EncodedKey);
        // System.out.println("Decoded Key Bytes Length: " + decodedKeyBytes.length);
    }
}
